package network.course3.ScheduledThreadPool;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

public class Animal implements Runnable{
    private String name;
    private int speed;
    private int length;
    private static final String DATE_TIME = "yyyy-MM-dd HH:mm:ss";
    private static final DateTimeFormatter formatter = DateTimeFormatter.ofPattern(DATE_TIME);
    public Animal(String name, int speed, int length) {
        super();
        this.name = name;
        this.speed = speed;
        this.length = length;
    }
    @Override
    public void run() {
        int sum=0;
        // TODO 自动生成的方法存根
        if (length>0){

                sum+=speed;
                length-=speed;
                System.out.println(name+"跑了"+sum+"米，距离终点还有"+length+"米");
            System.out.println(LocalDateTime.now().format(formatter));
            if(sum==2000){
                System.out.println(name+"到达终点");
                return;
            }
        }
    }
}